﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace android_charge.compent
{
    public partial class TriangleButton : Button
    {
        public TriangleButton()
        {
            InitializeComponent();
            this.FlatStyle = FlatStyle.Flat;    // 使用Flat样式
            this.FlatAppearance.BorderSize = 0; // 隐藏边框
            this.BackColor = Color.Transparent; // 背景透明
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);

            // 获取图形对象
            Graphics g = pe.Graphics;

            // 创建表示向右箭头的三角形的点
            Point[] arrowPoints = new Point[3];
            arrowPoints[0] = new Point(this.Width, 0);                // 右上角
            arrowPoints[1] = new Point(this.Width, this.Height);      // 右下角
            arrowPoints[2] = new Point(0, this.Height / 2);

            // 定义填充箭头的画刷，可以自定义颜色
            Brush brush = new SolidBrush(Color.Gray);

            // 填充箭头
            g.FillPolygon(brush, arrowPoints);

            // 如果想在按钮上绘制文本，需要手动绘制
            /*TextRenderer.DrawText(g, this.Text, this.Font, this.ClientRectangle, this.ForeColor,
                TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);*/
        }
    }
}
